<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 * @property int $id
 * @property string $account
 * @property string $code
 * @property int $expire_time
 * @property \Carbon\Carbon $create_time
 * @property \Carbon\Carbon $update_time
 * @property int $delete_time
 */
class SendCodeLog extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'send_code_log';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'expire_time' => 'integer', 'create_time' => 'datetime', 'update_time' => 'datetime', 'delete_time' => 'integer'];

    /**
     * 增加一条短信发送记录.
     * @param $account
     * @param $code
     * @param int $expireTime
     */
    public function addLog($account, $code, $expireTime = 0): int
    {
        $expireTime = empty($expireTime) ? time() + 300 : $expireTime;
        $this->account = $account;
        $this->code = $code;
        $this->expire_time = $expireTime;
        $this->save();
        return $this->id;
    }
}
